Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content-type and filename params for file upload #47

Merged
merged 6 commits into from
Dec 22, 2023

Conversation

MrRTi
Copy link
Contributor

@MrRTi MrRTi commented Sep 20, 2023

Currently all files are sent with type application/octet-stream. This update will add ability to pass content_type and filename as args if needed

Actual:
image

{
    "message": {
      ...
        "file": {
            ...
            "type": "application/octet-stream"
        },

Expected:
image

{
    "message": {
      ...
        "file": {
            ...
            "type": "image/jpeg"
        },

@MrRTi MrRTi force-pushed the feature/add-content-type-for-file-upload branch from dbeae1b to 9761f19 Compare September 20, 2023 12:58
@MrRTi MrRTi marked this pull request as draft September 20, 2023 13:53
@MrRTi MrRTi marked this pull request as ready for review September 20, 2023 14:43
Copy link
Owner

@abrom abrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @MrRTi 👍

Although I noticed a few things that I think will need some attention before merging

lib/rocket_chat/messages/room.rb Outdated Show resolved Hide resolved
@@ -110,7 +110,7 @@ def create_request(path, options)
req = Net::HTTP::Post.new(path, headers)
add_body(req, body) if body

form_data = reject_nils(options[:form_data])
form_data = options[:form_data]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would appear to be a breaking change. Can you explain why you've made it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will be a breaking change and here is why:

  1. reject_nils expect hash, form data in this update will be array.
  2. form_data was added in my prev PR with file upload and wasn't supported previously in any requests. reject_nils for json-bodies are still at row 107
  3. form_data is added in lib/rocket_chat/messages/room.rb:322 by transforming provided hash to an array of arrays.
    3.1. If some params passed by user are nil they will be cleaned out by compact at lib/rocket_chat/messages/room.rb:350
    3.2. If file-related optional params (filename, content-type) are nil they will be cleared at lib/rocket_chat/messages/room.rb:353
    3.3. I don't see any possible way to receive an array with nil element at lib/rocket_chat/messages/room.rb:354 with 3.1. and 3.2.

On the other hand, for future development, part of file_upload_array at lines lib/rocket_chat/messages/room.rb:352-358 could be moved to request helper to cover all form_data requests from any future endpoints. I could do this in separate PR if this is ok

@abrom abrom merged commit 2628a91 into abrom:main Dec 22, 2023
5 checks passed
@abrom
Copy link
Owner

abrom commented Dec 22, 2023

Apologies for the delay in actioning this @MrRTi

Update has been released in v0.2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants